//sdk方式调用接口
import serviceBase from "@/store/http/serviceBase";
export default {
	getUrlSearch(name) {
		// 未传参，返回空
		if (!name) return null;
		// 查询参数：先通过search取值，如果取不到就通过hash来取
		var after = window.location.search;
		after = after.substr(1) || window.location.hash.split("?")[1];
		// 地址栏URL没有查询参数，返回空
		if (!after) return null;
		// 如果查询参数中没有"name"，返回空
		if (after.indexOf(name) === -1) return null;

		var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
		// 当地址栏参数存在中文时，需要解码，不然会乱码
		var r = decodeURI(after).match(reg);
		// 如果url中"name"没有值，返回空
		if (!r) return null;

		return r[2];
	},

	async admGet(params, queryName) {
		var path = "/relation-web/admPost/" + queryName;
		var result = await serviceBase.GetJson(path, params);
		return result;
	},

	async admPost(params, queryName) {
		var path = "/relation-web/admPost/" + queryName;
		var result = await serviceBase.PostJson(path, params);
		return result;
	},
	async jumpPost(params, queryName) {
		let host = window.location.origin
		let arr = host.split('.')
		let url = ''
		for(let i = 0;i<arr.length-1;i++){
			url=url+arr[i]+'.'
		}
		url = url+'top'
		var path = url+"/relation-web/admPost/" + queryName;
		var result = await serviceBase.PostJson(path, params);
		return result;
	},
	async verifyPost(params, queryName) {
		var path = "/relotionVerifyi-knowledge-post/" + queryName;
		var result = await serviceBase.PostJson(path, params);
		return result;
	},
	async otherGet( queryName) {
		let domain =  window.location.host
		let hostHead = domain.split('.')[0]
		// let url = '.yushu.cloud/meoi-aim-server/graph/legend/query/'
		 let url ='.meos.net.cn/meos-control-server/graph/legend/query/'
		switch(hostHead){
			case 'dev': url = 'https://dev-gw' + url
			break;
			case 'qa': url = 'https://qa-gw' + url
			break;
			case 'pre': url = 'https://pre-gw' + url
			break;
			// case 'www': url = 'https://paasgw.yushu.cloud/apm-aim/graph/legend/query/' 
			case 'www': url = 'https://gw.meos.net.cn/meos-control-server/graph/legend/query/' 
			break;
			default : url = 'https://qa-gw' + url
		}
		
		var path = url + queryName;
		var result = await serviceBase.GetJson(path, true);
		return result;
	},
	// async otherGet( queryName) {
	// 	let url = 'http://192.168.17.175:3001/usersList?query='
	// 	var path = url + queryName;
	// 	var result = await serviceBase.GetJson(path, true);
	// 	return result;
	// },
	async otherPost( queryName) {
		let domain =  window.location.host
		let hostHead = domain.split('.')[0]
		let url = '.yushu.cloud/meos-control-server/graph/legend/query/'
		switch(hostHead){
			case 'dev': url = 'https://dev-gw' + url
			break;
			case 'qa': url = 'https://qa-gw' + url
			break;
			case 'pre': url = 'https://pre-gw' + url
			break;
			// 暂时  未上线
			// case 'www': url = 'https://paasgw.yushu.cloud/apm-aim/graph/legend/query/'
			case 'www': url = 'https://gw.yushu.cloud/meos-control-server/graph/legend/query/' 
			break;
			default : url = 'https://qa-gw' + url
		}
		
		var path = url + queryName;
		var result = await serviceBase.PostJson(path, {});
		return result;
	},
	async loginPost( queryName) {
		let domain =  window.location.host
		let hostHead = domain.split('.')[0]
		let url = '/mid-permission-server/Spring/MVC/entrance/unifier/login'
		// switch(hostHead){
		// 	case 'dev': url = 'https://dev-b.yushu.cloud' + url
		// 	break;
		// 	case 'qa': url = 'https://qa-b.yushu.cloud' + url
		// 	break;
		// 	case 'pre': url = 'https://pre-b.yushu.cloud' + url
		// 	break;
		// 	case 'www': url = 'https://b.yushu.cloud' + url
		// 	break;
		// 	default : url = 'https://dev-b.yushu.cloud' + url
			
		// }
		// var path = url ;
		
		var path = '/relation-web/loginPost'+url ;
		var result = await serviceBase.PostJson(path, queryName);
		return result;
	},
	async loginInfoPost( queryName,newUrl) {
		let domain =  window.location.host
		let hostHead = domain.split('.')[0]
		
		
		let url = '/mid-permission-server/Spring/MVC/entrance/unifier/getDataPermissionsByUserId'
		if(newUrl){
			url = newUrl
		}
		// switch(hostHead){
		// 	case 'dev': url = 'https://dev-dtx.ysbdtp.cn' + url
		// 	break;
		// 	case 'qa': url = 'https://qa-dtx.ysbdtp.cn' + url
		// 	break;
		// 	case 'pre': url = 'https://pre-dtx.ysbdtp.cn' + url
		// 	break;
		// 	// 暂时  未上线
		// 	// case 'www': url = 'https://paasgw.yushu.cloud/apm-aim/graph/legend/query/'
		// 	case 'www': url = 'https://dtx.ysbdtp.cn' + url
		// 	break;
		// 	default : url = 'https://dev-dtx.ysbdtp.cn' + url
		// }
		
		// var path = url ;
		var path = '/relation-web/loginPost'+url ;
		var result = await serviceBase.PostJson(path, queryName);
		return result;
	},
};
